namespace Yaaf.WP7.NativeAccess.IO
{
    using System;
    using System.Linq;
    using System.Xml.Linq;

    using Microsoft.Xna.Framework;

    public class DeviceInfo
    {
        public const string TempDir = "TEMPFILES";

        private static Guid? applicationId;

        public static Guid ApplicationId
        {
            get
            {
                if (applicationId == null)
                {
                    using (var strm = TitleContainer.OpenStream("WMAppManifest.xml"))
                    {
                        var xml = XElement.Load(strm);
                        string prodId = (from app in xml.Descendants("App")
                                         select app.Attribute("ProductID").Value).FirstOrDefault();
                        if (string.IsNullOrEmpty(prodId)) return Guid.Empty;

                        applicationId = new Guid(prodId);
                    }
                }

                return applicationId.Value;
            }
        }

    }
}